package com.shambles.manage2.tkmapper.mapper;

import com.shambles.manage.model.dto.SubScribeDTO;
import com.shambles.manage2.tkmapper.entity.AbattoirBooth;
import com.shambles.manage2.tkmapper.entity.SubscribeInformation;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.additional.insert.InsertListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

@org.apache.ibatis.annotations.Mapper
public interface SubscribeInformationMapper extends Mapper<SubscribeInformation>, InsertListMapper<SubscribeInformation> {
    AbattoirBooth isConflict(SubScribeDTO subScribeDTO);
    @Select("SELECT * FROM subscribe_information WHERE current_time_now > ${time0}")
    List<SubscribeInformation> staffList(long time0);

    List<SubscribeInformation> findCheckSubscribe(Integer status);

    List<SubscribeInformation> findAllSubscribe();

    Integer deal(SubscribeInformation information);

    SubscribeInformation findOpenIdByID(Integer id);

    @Update("UPDATE subscribe_information SET status = ${status} WHERE guid = '${guid}'"  )
    void updateState(@Param("status") int status , @Param("guid") String guid);

    //@Select("SELECT c.guid,c.type name,IFNULL(scount.number,0)  value FROM cattle c LEFT JOIN  (SELECT sd.cattle_guid,sd.type,sum(sd.number) number FROM subscribe_information si INNER JOIN subscribe_detail sd ON si.subscribe_time >${startTime} and si.subscribe_time< ${endTime} AND si.`status` = 0 AND si.guid = sd.subscribe_guid GROUP BY sd.cattle_guid) scount ON c.guid = scount.cattle_guid")
    @Select("SELECT c.guid,c.type name,IFNULL(scount.number,0)  value FROM cattle c LEFT JOIN  (SELECT sd.cattle_guid,sd.type,sum(sd.number) number FROM subscribe_information si INNER JOIN subscribe_detail sd ON si.subscribe_time >${startTime} and si.subscribe_time< ${endTime} AND si.guid = sd.subscribe_guid GROUP BY sd.cattle_guid) scount ON c.guid = scount.cattle_guid")
    List<Map<String, Object>> count(@Param("startTime") Long startTime,@Param("endTime") Long endTime);

    void updateById(SubscribeInformation information);


}